package com.kim.smartring.activity.fragment;

import java.util.Calendar;
import java.util.List;

import android.annotation.SuppressLint;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.kim.smartring.R;
import com.kim.smartring.adapter.SummaryDataAdapter;
import com.kim.smartring.ble.BleWrapperUiCallbacks;
import com.kim.smartring.utils.DialogUtils;

@SuppressLint("ValidFragment")
public class SmartRingMainFragment extends BaseFragment implements
		View.OnClickListener {

	private ImageView img_menu;

	private ViewPager viewPager;
	private SummaryDataAdapter summaryDataAdapter;
	private int vpIndex;

	private TextView txtTimePicker;
	private ImageView imgLeft;
	private ImageView imgRight;

	public SmartRingMainFragment() {
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// construct the RelativeLayout
		View view = inflater.inflate(R.layout.main_layout, null);
		viewPager = (ViewPager) view.findViewById(R.id.vp_summary);
		img_menu = (ImageView) view.findViewById(R.id.img_menu);
		txtTimePicker = (TextView) view.findViewById(R.id.txt_date);
		imgLeft = (ImageView) view.findViewById(R.id.img_left);
		imgRight = (ImageView) view.findViewById(R.id.img_right);
		img_menu.setOnClickListener(this);
		txtTimePicker.setOnClickListener(this);
		imgLeft.setOnClickListener(this);
		imgRight.setOnClickListener(this);
		return view;
	}

	@Override
	public void onResume() {
		super.onResume();
		viewPager.setAdapter(new SummaryDataAdapter(getActivity(), null, null));
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.img_menu:
			showSlidingMenu();
			break;
		case R.id.txt_date:
			DialogUtils.showDateSettingDialog(Calendar.getInstance(),
					getActivity(), new OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog, int which) {

						}
					}, R.string.label_change_date);
			break;
		case R.id.img_left:
			vpIndex = viewPager.getCurrentItem();
			if ((vpIndex += 1) >= 3) {
				vpIndex = 3;
			}
			viewPager.setCurrentItem(vpIndex);
			break;
		case R.id.img_right:
			vpIndex = viewPager.getCurrentItem();
			if ((vpIndex -= 1) <= 1) {
				vpIndex = 1;
			}
			viewPager.setCurrentItem(vpIndex);
			break;
		default:
			break;
		}
	}

}
